package com.itheima.service.impl;

import com.itheima.mapper.DataStatisticsMapper;
import com.itheima.pojo.EmpJobCategory;
import com.itheima.pojo.vo.DataStatistics;
import com.itheima.pojo.vo.EmpJobData;
import com.itheima.pojo.vo.StuCountData;
import com.itheima.service.DataStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DataStatisticsServiceImpl implements DataStatisticsService {
    @Autowired
    private DataStatisticsMapper dataStatisticsMapper;

    @Override
    public List<DataStatistics> statistics() {
        Long manCount = dataStatisticsMapper.selectManCount();
        Long woManCount = dataStatisticsMapper.selectWomanCount();
        List<DataStatistics> dataStatisticsList = new ArrayList<>();
        dataStatisticsList.add(new DataStatistics("男性员工",manCount));
        dataStatisticsList.add(new DataStatistics("女性员工",woManCount));
        return dataStatisticsList;
    }

    @Override
    public EmpJobData findCategories() {
        List<EmpJobCategory> empJobCategoryList = dataStatisticsMapper.findCategories();
        List<String> nameList = new ArrayList<>();
        List<Long> countList = new ArrayList<>();
        for (EmpJobCategory empJobCategory : empJobCategoryList) {
            nameList.add(empJobCategory.getName());
            countList.add(empJobCategory.getCount());
        }
        EmpJobData empJobData = new EmpJobData(nameList,countList);
       return empJobData;
    }

    @Override
    public List<DataStatistics> studentDegreeData() {
        List<DataStatistics> dataStatisticsList = dataStatisticsMapper.studentDegreeData();
        return dataStatisticsList;
    }

    @Override
    public StuCountData studentCountData() {
        List<EmpJobCategory> empJobCategoryList = dataStatisticsMapper.findClazzList();
        List<String> clazzList = new ArrayList<>();
        List<Long> dataList = new ArrayList<>();
        for (EmpJobCategory empJobCategory : empJobCategoryList) {
            clazzList.add(empJobCategory.getName());
            dataList.add(empJobCategory.getCount());
        }
        StuCountData stuCountData = new StuCountData(clazzList,dataList);
        return stuCountData;
    }
}
